<%-- 
    Document   : loggedin
    Created on : Jan 13, 2012, 10:15:00 PM
    Author     : Korn Marcelo & Ruchlis Oleg
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>logged in Page</title>
        <link rel="stylesheet" type="text/css" href="ex4_css.css" title="myStyle">
    </head>
    <body>
        <%
            // checking if this session belongs to user that went
            // through the authentication properly.
            String username = (String)session.getAttribute("username");
            if (username != null)
            {
                out.println("<div align=\"right\"> <a href=\"logout.jsp\">logout</a></div>");
                out.println("<h1> Welcome " + username + "!</h1>");
                out.println("<p> Who is logged in: <br>");
                
                // getting the list of all logged in users
                String usersString = application.getAttribute("users").toString();
                String[] usersList = usersString.split("\r\n");
                // printing each logged user
                for(String user : usersList)
                    out.println(user + "<br>");
                out.println("</p>");
            }
            // user entered this page without authentication, therefor
            // he will be redirected to the login page.
            else
            {
        %>
    <jsp:forward page="index.jsp"/>
        <%
            }
        %>
    </body>
</html>
